import { patrolingCruise } from "@/api/remote-control.js";
import usePatrolingStore from "@/store/patroling";

/*
 * @Author: ReinerLau lk850593913@gmail.com
 * @Date: 2023-01-31 15:22:38
 * @LastEditors: ReinerLau lk850593913@gmail.com
 * @LastEditTime: 2023-02-23 17:24:12
 * @FilePath: \v2.0.0\src\views\patroling\shared\index.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
export const modes = {
  STOP: 1,
  AUTO: 4,
  MANUAL: 3,
};

export interface PatrolingInfo {
  robotid?: string;
  customMode?: number;
  baseMode?: number;
  battery?: number;
  latitude?: number;
  longitude?: number;
  heading?: number;
  missionId?: number;
}

export const baseModes = {
  AUTO: 129,
  MANUAL: 1,
  STOP: 0,
};

export function controlDevice(data) {
  patrolingCruise(data);
}

export interface websocketData {
  id: string;
  type: string;
  message: string;
  time?: string;
}

export function createRedArrow(heading) {
  const c = document.createElement("canvas");
  c.width = 24;
  c.height = 24;
  const ctx = c.getContext("2d");
  ctx.translate(c.width * 0.5, c.height * 0.5);
  ctx.rotate((heading * Math.PI) / 180);
  ctx.translate(-c.width * 0.5, -c.height * 0.5);
  ctx.fillStyle = "#f00";
  ctx.beginPath();
  ctx.moveTo(12, 0);
  ctx.lineTo(5, 20);
  ctx.lineTo(12, 15);
  ctx.lineTo(19, 20);
  ctx.lineTo(12, 0);
  ctx.closePath();
  ctx.fill();
  ctx.stroke();
  return c.toDataURL();
}

const patrolingData = usePatrolingStore();
export function selectedCar() {
  return patrolingData.patrolingInfo.robotid;
}
